<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>CSS Style Attributes</title>
  <link rel=contents href="#contents">
  <link rel=index href="#index">
  <link rel="stylesheet" type="text/css" href="../default.css">
  <link href="../csslogo.ico" rel="shortcut icon" type="image/x-icon">
  <link rel="stylesheet" type="text/css" href="https://www.w3.org/StyleSheets/TR/W3C-[STATUS].css">
  <script defer=defer
    src="https://test.csswg.org/harness/annotate.js#css-style-attr-1_dev"
    type="text/javascript"></script>
</head>

<body class="h-entry">

<div class="head">
<!--logo-->

<h1 class="p-name">CSS Style Attributes</h1>

<h2 class="no-num no-toc">[LONGSTATUS] <span class="dt-updated"><span class="value-title" title="[CDATE]">[DATE]</span></span></h2>
<dl>
  <dt>This version:</dt>
    <dd><a class="u-url" href="[VERSION]">[VERSION]</a>

  <dt>Latest version:
    <dd><a href="https://www.w3.org/TR/[SHORTNAME]/">https://www.w3.org/TR/[SHORTNAME]/</a>

  <dt>Editor's draft:
    <dd><a href="https://drafts.csswg.org/[SHORTNAME]/">https://drafts.csswg.org/[SHORTNAME]/</a>
    (<a href="https://hg.csswg.org/drafts/log/tip/[SHORTNAME]/Overview.src.html">change log</a>)

  <dt>Previous version:
    <dd><a href="https://www.w3.org/TR/2013/PR-css-style-attr-20131003/">https://www.w3.org/TR/2013/PR-css-style-attr-20131003/</a>
    
  <dt>Feedback:
      <dd><a href="mailto:www-style@w3.org?subject=%5Bcss-style-attr%5D%20feedback">www-style@w3.org</a>
          with subject line &ldquo;<kbd>[[SHORTNAME]] <var>&hellip; message topic &hellip;</var></kbd>&rdquo;
          (<a rel="discussion" href="http://lists.w3.org/Archives/Public/www-style/">archives</a>)

  <dt>Editors:
    <dd class="p-author h-card vcard">
      <a lang="tr" class="p-name fn u-url url" rel="author"
         href="http://tantek.com/">Tantek &Ccedil;elik</a>
      (<a class="p-org org h-org"
          href="https://mozilla.org/">Mozilla</a>, 
       and formerly at 
       <a href="http://microsoft.com/">Microsoft Corporation</a>)
     &lt;<a class="u-email email"
href="mailto:tantek@cs.stanford.edu">tantek@cs.stanford.edu</a>&gt;
    </dd>
    <dd class="p-author h-card vcard">
      <a class="p-name fn n u-url url" rel="author"
         href="http://fantasai.inkedblade.net/contact"><span class="p-given-name given-name">Elika</span> 
         <abbr class="p-additional-name additional-name">J.</abbr>
         <span class="p-family-name family-name">Etemad</span></a> 
      (<a class="p-org org h-org"
          href="https://mozilla.org/">Mozilla</a>)
    </dd>
  <dt>Previous Editors:
    <dd class="vcard"><a class="fn url" href="http://www.w3.org/People/Bos/">Bert Bos</a> (<a class="org" href="http://www.w3.org/">W3C</a>), &lt;<a class="email" href="mailto:bert@w3.org">bert@w3.org</a>&gt;
    </dd>
    <dd class="vcard"><span class="fn">Marc Attinasi</span> (<span class="org">AOL/Netscape</span>), &lt;<a class="email" href="mailto:attinasi@netscape.com">attinasi@netscape.com</a>&gt;
    </dd>
    <dt>Test suite:</dt>
      <dd>
        <a href="http://test.csswg.org/suites/css-style-attr/nightly-unstable/">http://test.csswg.org/suites/css-style-attr/nightly-unstable/</a>
      </dd>
</dl>
<!--begin-copyright-->
<p>[Here will be included the file "../copyright.inc"]</p>
<!--end-copyright-->

<hr title="Separator for header">
</div>

<h2 class="no-num no-toc" id="abstract">Abstract</h2>

<p><span class="p-summary">
Markup languages such as HTML [[HTML401]] and SVG [[SVG11]] provide a style
attribute on most elements, to hold inline style information that applies
to those elements. This
module describes the syntax and interpretation of the CSS fragment that can
be used in such style attributes.
</span>

<h2 class="no-num no-toc" id="status">Status of this document</h2>
<!--status-->

<nav id="toc">
<h2 class="no-num no-toc" id="contents">Table of contents</h2>
<!--toc-->
</nav>

<h2 id="intro">Introduction</h2>

<p>Some document formats have a <dfn>style attribute</dfn> to permit
the author to directly apply style information to specific elements
in documents. If a document format defines a style attribute (whether named 'style' or something else) and the
attribute accepts CSS as its value, then this specification defines that
<span id=style-attribute0>style attribute</span>&rsquo;s syntax and interpretation.

<div class="example">
  <p>The following example shows the use of the <code>style</code> attribute
  in HTML [[HTML401]]:</p>
  <pre>&lt;p style="<em>color: #090; line-height: 1.2</em>"&gt;...&lt;/p&gt;</pre>
</div>

<h2 id="conformance">Conformance</h2>

<p>A document or implementation cannot conform to CSS Style Attributes alone, but can claim conformance to CSS Style Attributes
if it satisfies the conformance requirements in this specification when
implementing CSS together with style attribute handling as defined in a
document language that has one or more CSS style attributes.</p>

<p>Conformance to CSS Style Attributes is defined for two
classes:
<dl>
  <dt><dfn>document</dfn></dt>
    <dd>A document represented in a document language that defines a style
      attribute for one or more of its elements.
  <dt><dfn>interpreter</dfn></dt>
    <dd>Someone or something that interprets the semantics of a document and
      its associated style information.
      (Most CSS <a href="https://www.w3.org/TR/CSS21/conform.html#user-agent">user
      agents</a> fall under this category.)</dd>
</dl>

<p>The conformance requirements are expressed with a combination of
  descriptive assertions and RFC 2119 terminology. The key words "MUST",
  "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT",
  "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this
  document are to be interpreted as described in RFC 2119.
  However, for readability, these words do not appear in all uppercase
  letters in this specification. All of the text of this specification is
  normative except sections explicitly marked as non-normative, examples,
  and notes. [[!RFC2119]]</p>

<p>Examples in this specification are introduced with the words "for example"
  or are set apart from the normative text with <code>class="example"</code>,
  like this:

<div class="example">
  <p>This is an example of an informative example.</p>
</div>

<p>Informative notes begin with the word "Note" and are set apart from the
  normative text with <code>class="note"</code>, like this:

<p class="note">Note, this is an informative note.</p>

<h2 id="syntax">Syntax and Parsing</h2>

<p>The value of the style attribute must match the syntax of the contents of
a CSS <a href="https://www.w3.org/TR/CSS21/syndata.html#rule-sets">declaration
block</a> (excluding the delimiting braces), whose formal grammar is given
below in the terms and conventions of the
<a href="https://www.w3.org/TR/CSS21/syndata.html#syntax">CSS core grammar</a>:

<pre>
style-attribute
  : S* declaration-list
  ;

declaration-list
    : declaration [ ';' S* declaration-list ]?
    | at-rule declaration-list
    | /* empty */
    ;
</pre>

<p class="note">Note that following the CSS2.1 convention, comment tokens
are not shown in the rule above.

<p>The interpreter must parse the style attribute's value using the
same forward-compatible parsing rules that apply to parsing declaration block
contents in a normal CSS style sheet (see
<a href="https://www.w3.org/TR/CSS21/syndata.html">chapter 4 of the CSS2.1
specification</a> [[!CSS21]]),
with the following addition: when the UA expects the start of a declaration or at-rule
(i.e., an IDENT token or an ATKEYWORD token) but finds an unexpected token instead,
that token is considered to be the first token of a malformed declaration.
I.e., the rule for malformed declarations, rather than malformed statements,
is used to determine which tokens to ignore in that case.

<p class="note">Note that because there is no open brace delimiting the
declaration list in the CSS style attribute syntax, a close brace
(<code>}</code>) in the style attribute's value does not terminate the
style data: it is merely an invalid token.</p>

<div class="note">
<p>Although the grammar allows it,
no at-rule valid in style attributes is define at the moment.
The forward-compatible parsing rules are such that a declaration following an at-rule
is not ignored:
<pre>&lt;span style="@unsupported { splines: reticulating } color: green"></pre>
</div>

<h2 id="interpret">Cascading and Interpretation</h2>

<p>The declarations in a style attribute apply to the element to which
the attribute belongs. In the cascade, these declarations are considered
to have author origin and a specificity higher than any selector.
CSS2.1 <a href="https://www.w3.org/TR/CSS21/cascade.html#specificity">defines</a>
how style sheets and style attributes are cascaded together. [[!CSS21]]
Relative URLs in the style data must be resolved relative to the style attribute's element (or to the document if per-element resolution is not
defined) when the attribute's value is parsed<!-- so dynamic changes to
the base URL don't affect the CSS ~Hixie -->.

<p>Aside from the differences in cascading, the declarations in a style
attribute must be interpreted exactly as if they were given in a CSS
style rule that applies to the element.

<p>The CSS Working Group strongly recommends that document languages do
not allow multiple CSS style attributes on a single element. If a document
language allows multiple CSS style attributes, each must be parsed
independently and treated as a separate style rule, the ordering of which
should be defined by the document language, else is undefined.

<h2 id="changes">Changes</h2>

Changes since the <a href="https://www.w3.org/TR/2013/PR-css-style-attr-20131003/">2013-10-03 Proposed Recommendation</a> are:

<ul>
  <li>Parse at-rules in declaration lists to allow future extension.
</ul>

<h2 id="ack">Acknowledgments</h2>

<p>Thanks to feedback from <span class="vcard"><span class="fn">Daniel Glazman</span></span>, <span class="vcard"><span class="fn">Ian Hickson</span></span>, <span class="vcard"><span class="fn n"><span class="given-name">Eric</span> <abbr class="additional-name">A.</abbr> <span class="family-name">Meyer</span></span></span>,
<span class="vcard"><span class="fn">Bj&ouml;rn H&ouml;hrmann</span></span>.
</p>

<h2 id="references">References

<h3 class="no-num" id="normative-references">Normative references</h3>

<!--begin-normative-->
<p>[Here will be inserted the file "normative.inc"]</p>
<!--end-normative-->

<h3 class="no-num" id="informative-references">Informative references</h3>

<!--begin-informative-->
<p>[Here will be inserted the file "informative.inc"]</p>
<!--end-informative-->

</body>
</html>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-declaration:"~/SGML/HTML4.decl"
sgml-default-doctype-name:"html"
sgml-minimize-attributes:t
sgml-nofill-elements:("pre" "style" "br")
End:
-->
